package pacmanbfs;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Solution {
	/* Head ends here */
	private static Queue<Integer> explore_x = new LinkedList<Integer>(), explore_y = new LinkedList<Integer>();
	private static List<Integer> explored_x = new ArrayList<Integer>(), explored_y = new ArrayList<Integer>();
	private static boolean next(int x, int y, int cx, int cy, int nx, int ny, char[][] grid, int[][] prev_x, int[][] prev_y, int[][] dist) {
		if(nx >= 0 && nx < x && ny >= 0 && ny < y && (grid[nx][ny] == '-' || grid[nx][ny] == '.')) {
			explored_x.add(nx);
			explored_y.add(ny);
			prev_x[nx][ny] = cx;
			prev_y[nx][ny] = cy;
			dist[nx][ny] = dist[cx][cy] + 1;
			if(grid[nx][ny] == '-') {
				grid[nx][ny] = 'v';
				explore_x.add(nx);
				explore_y.add(ny);
			}
			return grid[nx][ny] == '.';
		}
		return false;
	}
	private static void print(int[][] prev_x, int[][] prev_y, int cx, int cy, int pacman_x, int pacman_y) {
		if(cx != pacman_x || cy != pacman_y)
			print(prev_x, prev_y, prev_x[cx][cy], prev_y[cx][cy], pacman_x, pacman_y);
		System.out.println(cx + " " + cy);
	}
	static void nextMove(int x, int y, int pacman_x, int pacman_y, int food_x, int food_y, char[][] grid) {
		int[][] prev_x = new int[x][y], prev_y = new int[x][y], dist = new int[x][y];
		explored_x.add(pacman_x);
		explored_y.add(pacman_y);
		explore_x.add(pacman_x);
		explore_y.add(pacman_y);
		while(!explore_x.isEmpty()) {
			int cx = explore_x.remove(), cy = explore_y.remove();
			if(next(x, y, cx, cy, cx - 1, cy, grid, prev_x, prev_y, dist))
				break;
			if(next(x, y, cx, cy, cx, cy - 1, grid, prev_x, prev_y, dist))
				break;
			if(next(x, y, cx, cy, cx, cy + 1, grid, prev_x, prev_y, dist))
				break;
			if(next(x, y, cx, cy, cx + 1, cy, grid, prev_x, prev_y, dist))
				break;
		}
		System.out.println(explored_x.size());
		for(int i = 0; i < explored_x.size(); i++)
			System.out.println(explored_x.get(i) + " " + explored_y.get(i));
		System.out.println(dist[food_x][food_y]);
		print(prev_x, prev_y, food_x, food_y, pacman_x, pacman_y);
	}
	static void nextMove(int x, int y, int pacman_x, int pacman_y, int food_x, int food_y, String [] grid) {
		char[][] cGrid = new char[x][y];
		for(int i = 0; i < x; i++)
			cGrid[i] = grid[i].toCharArray();
		nextMove(x, y, pacman_x, pacman_y, food_x, food_y, cGrid);
	}
	/* Tail starts here */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int pacman_x = in.nextInt();
		int pacman_y = in.nextInt();

		int food_x = in.nextInt();
		int food_y = in.nextInt();

		int x = in.nextInt();
		int y = in.nextInt();

		String grid[] = new String[x];

		for(int i = 0; i < x; i++) {
			grid[i] = in.next();
		}
		in.close();
		
		nextMove( x, y, pacman_x, pacman_y, food_x, food_y, grid);
	}
}